package com.starlight.flower_server.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * @Author yfy2001
 * @date 2023/4/10 22:08
 */
@RestController
@RequestMapping("/file")
public class FileController {
    @PostMapping("/uploadPicture")
    public String uploadPicture(MultipartFile file){
        try {
            byte[] bytes = file.getBytes();
            Path path = Paths.get("C:\\Users\\yfy2001\\Desktop");
            Files.write(path,bytes);
            return path.toString();
        } catch (IOException e) {
            e.printStackTrace();
            return "文件上传失败";
        }
    }

}
